﻿using System;
using Autodesk.Revit.DB;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;
using YJKRGeometry;

namespace YJKArchMethodLibrary.StructurePoleSuit
{
	public class Structure2DPole
	{
		public ElementId ComponentId
		{
			get
			{
				return this.m_ComponentId;
			}
		}

		public bool IsPositiveDirection
		{
			get
			{
				return this.m_PositiveDirection;
			}
		}

		public bool IsArcPole
		{
			get
			{
				return !Geometry.IsEqual(this.m_Bulge, 0.0);
			}
		}

		public XYZ StartPoint
		{
			get
			{
				return this.m_ptStart;
			}
		}

		public XYZ EndPoint
		{
			get
			{
				return this.m_ptEnd;
			}
		}

		public XYZ PositiveStartPoint
		{
			get
			{
				return this.m_ptPositiveStart;
			}
			set
			{
				this.m_ptPositiveStart = value;
			}
		}

		public XYZ PositiveEndPoint
		{
			get
			{
				return this.m_ptPositiveEnd;
			}
			set
			{
				this.m_ptPositiveEnd = value;
			}
		}

		public XYZ NegativeStartPoint
		{
			get
			{
				return this.m_ptNegativeStart;
			}
			set
			{
				this.m_ptNegativeStart = value;
			}
		}

		public XYZ NegativeEndPoint
		{
			get
			{
				return this.m_ptNegativeEnd;
			}
			set
			{
				this.m_ptNegativeEnd = value;
			}
		}

		public Edge VariableCross_SectionInPositiveStart
		{
			get
			{
				return this.m_VariableCross_SectionInPositiveStart;
			}
		}

		public Edge VariableCross_SectionInPositiveEnd
		{
			get
			{
				return this.m_VariableCross_SectionInPositiveEnd;
			}
		}

		public Edge VariableCross_SectionInNegativeStart
		{
			get
			{
				return this.m_VariableCross_SectionInNegativeStart;
			}
		}

		public Edge VariableCross_SectionInNegativeEnd
		{
			get
			{
				return this.m_VariableCross_SectionInNegativeEnd;
			}
		}

		public double Bulge
		{
			get
			{
				return this.m_Bulge;
			}
		}

		public double PositiveHalfWidth
		{
			get
			{
				double result;
				if (this.IsArcPole)
				{
					XYZ xyz = null;
					Geometry.GetCenterWithBulge(this.m_ptStart, this.m_ptEnd, this.m_Bulge, ref xyz);
					result = this.m_ptPositiveStart.DistanceTo(xyz) - this.Radius;
				}
				else
				{
					result = Geometry.CalculateFootPoint(this.m_ptStart, this.m_ptEnd, this.m_ptPositiveStart).DistanceTo(this.m_ptPositiveStart);
				}
				return result;
			}
		}

		public double NegativeHalfWidth
		{
			get
			{
				double result;
				if (this.IsArcPole)
				{
					XYZ xyz = null;
					Geometry.GetCenterWithBulge(this.m_ptStart, this.m_ptEnd, this.m_Bulge, ref xyz);
					result = this.Radius - this.m_ptNegativeStart.DistanceTo(xyz);
				}
				else
				{
					result = Geometry.CalculateFootPoint(this.m_ptStart, this.m_ptEnd, this.m_ptNegativeStart).DistanceTo(this.m_ptNegativeStart);
				}
				return result;
			}
		}

		public XYZ Center
		{
			get
			{
				if (Geometry.IsEqual(this.m_Bulge, 0.0))
				{
					return null;
				}
				XYZ result = null;
				Geometry.GetCenterWithBulge(this.m_ptStart, this.m_ptEnd, this.m_Bulge, ref result);
				return result;
			}
		}

		public double Radius
		{
			get
			{
				if (Geometry.IsEqual(this.m_Bulge, 0.0))
				{
					return double.MaxValue;
				}
				double result = 0.0;
				Geometry.GetRadiusWithBulge(this.m_ptStart, this.m_ptEnd, this.m_Bulge, ref result);
				return result;
			}
		}

		public double Length()
		{
			if (this.IsArcPole)
			{
				XYZ center = this.Center;
				double radius = this.Radius;
				double angle = Geometry.getAngle(center, this.m_ptStart);
				double angle2 = Geometry.getAngle(center, this.m_ptEnd);
				return Geometry.BetweenTheAngles(angle, angle2, true) * radius;
			}
			return this.m_ptStart.DistanceTo(this.m_ptEnd);
		}

		public double PositiveSideLineLength()
		{
			if (this.IsArcPole)
			{
				XYZ center = this.Center;
				double num = center.DistanceTo(this.m_ptPositiveStart);
				double angle = Geometry.getAngle(center, this.m_ptPositiveStart);
				double angle2 = Geometry.getAngle(center, this.m_ptPositiveEnd);
				return Geometry.BetweenTheAngles(angle, angle2, true) * num;
			}
			return this.m_ptPositiveStart.DistanceTo(this.m_ptPositiveEnd);
		}

		public double NegativeSideLineLength()
		{
			if (this.IsArcPole)
			{
				XYZ center = this.Center;
				double num = center.DistanceTo(this.m_ptNegativeStart);
				double angle = Geometry.getAngle(center, this.m_ptNegativeStart);
				double angle2 = Geometry.getAngle(center, this.m_ptNegativeEnd);
				return Geometry.BetweenTheAngles(angle, angle2, true) * num;
			}
			return this.m_ptNegativeStart.DistanceTo(this.m_ptNegativeEnd);
		}

		public XYZ CalculateFootPointOnAxis(XYZ pt)
		{
			if (this.IsArcPole)
			{
				XYZ center = this.Center;
				XYZ xyz = (pt - center).Normalize() * this.Radius;
				return center + xyz;
			}
			return Geometry.CalculateFootPoint(this.m_ptStart, this.m_ptEnd, pt);
		}

		public Structure2DPole._tagSideLineValidType IsValidSideLineOfPositive()
		{
			return this.IsValidSideLine(this.m_ptPositiveStart, this.m_ptPositiveEnd);
		}

		public Structure2DPole._tagSideLineValidType IsValidSideLineOfNegative()
		{
			return this.IsValidSideLine(this.m_ptNegativeStart, this.m_ptNegativeEnd);
		}

		private Structure2DPole._tagSideLineValidType IsValidSideLine(XYZ ptStartOfSideline, XYZ ptEndOfSideline)
		{
			if (ptStartOfSideline.IsAlmostEqualTo(ptEndOfSideline))
			{
				return Structure2DPole._tagSideLineValidType._ZeroLength;
			}
			if (this.IsArcPole)
			{
				XYZ center = this.Center;
				XYZ xyz = this.m_ptStart - center;
				XYZ xyz2 = this.m_ptEnd - center;
				XYZ xyz3 = xyz.CrossProduct(xyz2).Normalize();
				XYZ xyz4 = ptStartOfSideline - center;
				XYZ xyz5 = ptEndOfSideline - center;
				XYZ xyz6 = xyz4.CrossProduct(xyz5).Normalize();
				if (xyz3.IsAlmostEqualTo(xyz6))
				{
					return Structure2DPole._tagSideLineValidType._Valide;
				}
				return Structure2DPole._tagSideLineValidType._Reversed;
			}
			else
			{
				XYZ xyz7 = ptEndOfSideline - ptStartOfSideline;
				if (Geometry.LessThan((this.m_ptEnd - this.m_ptStart).AngleTo(xyz7), Math.PI*.5))
				{
					return Structure2DPole._tagSideLineValidType._Valide;
				}
				return Structure2DPole._tagSideLineValidType._Reversed;
			}
		}

		public bool SameAs(Structure2DPole rhs)
		{
			return (this.m_ptStart.IsAlmostEqualTo(rhs.m_ptStart, 0.0001) && this.m_ptEnd.IsAlmostEqualTo(rhs.m_ptEnd, 0.0001) && Geometry.IsEqual(this.m_Bulge, rhs.m_Bulge)) || (this.m_ptStart.IsAlmostEqualTo(rhs.m_ptEnd, 0.0001) && this.m_ptEnd.IsAlmostEqualTo(rhs.m_ptStart, 0.0001) && Geometry.IsEqual(-this.m_Bulge, rhs.m_Bulge));
		}

		public Structure2DPole._tagPositionType TestPointPositionType(XYZ ptCurNodePos)
		{
			double val = this.m_ptStartNodePosition.DistanceTo(ptCurNodePos);
			double val2 = this.m_ptEndNodePosition.DistanceTo(ptCurNodePos);
			if (Geometry.LessThan(val, val2))
			{
				return Structure2DPole._tagPositionType._StartNode;
			}
			if (Geometry.GreaterThan(val, val2))
			{
				return Structure2DPole._tagPositionType._EndNode;
			}
			return Structure2DPole._tagPositionType._OtherPoint;
		}

		public bool GetAngle(XYZ ptCurNodePos, ref double curAngle)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				if (!this.IsArcPole)
				{
					curAngle = Geometry.getAngle(this.m_ptStart, this.m_ptEnd);
				}
				else if (Geometry.LessThan(this.m_Bulge, 0.0))
				{
					XYZ ptCenter = new XYZ(0.0, 0.0, 0.0);
					Geometry.GetCenterWithBulge(this.m_ptStart, this.m_ptEnd, this.m_Bulge, ref ptCenter);
					curAngle = Geometry.getAngle(ptCenter, this.m_ptStart);
					curAngle = Geometry.formatAngle(curAngle - Math.PI*.5);
				}
				else
				{
					XYZ ptCenter2 = new XYZ(0.0, 0.0, 0.0);
					Geometry.GetCenterWithBulge(this.m_ptStart, this.m_ptEnd, this.m_Bulge, ref ptCenter2);
					curAngle = Geometry.getAngle(ptCenter2, this.m_ptStart);
					curAngle = Geometry.formatAngle(curAngle + Math.PI*.5);
				}
				return true;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				if (!this.IsArcPole)
				{
					curAngle = Geometry.getAngle(this.m_ptEnd, this.m_ptStart);
				}
				else if (Geometry.LessThan(this.m_Bulge, 0.0))
				{
					XYZ ptCenter3 = new XYZ(0.0, 0.0, 0.0);
					Geometry.GetCenterWithBulge(this.m_ptStart, this.m_ptEnd, this.m_Bulge, ref ptCenter3);
					curAngle = Geometry.getAngle(ptCenter3, this.m_ptEnd);
					curAngle = Geometry.formatAngle(curAngle + Math.PI*.5);
				}
				else
				{
					XYZ ptCenter4 = new XYZ(0.0, 0.0, 0.0);
					Geometry.GetCenterWithBulge(this.m_ptStart, this.m_ptEnd, this.m_Bulge, ref ptCenter4);
					curAngle = Geometry.getAngle(ptCenter4, this.m_ptEnd);
					curAngle = Geometry.formatAngle(curAngle - Math.PI*.5);
				}
				return true;
			}
			return false;
		}

		public bool GetWinding(XYZ ptCurNodePos, ref int winding)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				winding = 1;
				if (!this.IsArcPole)
				{
					winding = 0;
				}
				if (Geometry.LessThan(this.m_Bulge, 0.0))
				{
					winding = -1;
				}
				return true;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				winding = -1;
				if (!this.IsArcPole)
				{
					winding = 0;
				}
				if (Geometry.LessThan(this.m_Bulge, 0.0))
				{
					winding = 1;
				}
				return true;
			}
			return false;
		}

		public void SetIsPositiveDirection(XYZ ptCurNodePos)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				this.m_PositiveDirection = true;
				return;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				this.m_PositiveDirection = false;
			}
		}

		public XYZ CurOutNodePosition(XYZ ptCurNodePos)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				return this.m_ptEndNodePosition;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				return this.m_ptStartNodePosition;
			}
			return null;
		}

		public void SetCurInNodePosition(XYZ ptCurNodePos, XYZ newPosition)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				this.m_ptStartNodePosition = newPosition;
				return;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				this.m_ptEndNodePosition = newPosition;
			}
		}

		public double CurBulge(XYZ ptCurNodePos)
		{
			double result = 0.0;
			if (!this.IsArcPole)
			{
				return result;
			}
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				result = this.m_Bulge;
			}
			else if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				result = -this.m_Bulge;
			}
			return result;
		}

		public XYZ CurPositiveStartPoint(XYZ ptCurNodePos)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				return this.m_ptPositiveStart;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				return this.m_ptNegativeEnd;
			}
			return null;
		}

		public XYZ CurPositiveEndPoint(XYZ ptCurNodePos)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				return this.m_ptPositiveEnd;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				return this.m_ptNegativeStart;
			}
			return null;
		}

		public bool SetCurPositiveStartPoint(XYZ ptCurNodePos, XYZ ptNewPos)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				this.m_ptPositiveStart = ptNewPos;
				return true;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				this.m_ptNegativeEnd = ptNewPos;
				return true;
			}
			return false;
		}

		public bool SetCurPositiveEndPoint(XYZ ptCurNodePos, XYZ ptNewPos)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				this.m_ptPositiveEnd = ptNewPos;
				return true;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				this.m_ptNegativeStart = ptNewPos;
				return true;
			}
			return false;
		}

		public XYZ CurNegativeStartPoint(XYZ ptCurNodePos)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				return this.m_ptNegativeStart;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				return this.m_ptPositiveEnd;
			}
			return null;
		}

		public XYZ CurNegativeEndPoint(XYZ ptCurNodePos)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				return this.m_ptNegativeEnd;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				return this.m_ptPositiveStart;
			}
			return null;
		}

		public bool SetCurNegativeStartPoint(XYZ ptCurNodePos, XYZ ptNewPos)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				this.m_ptNegativeStart = ptNewPos;
				return true;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				this.m_ptPositiveEnd = ptNewPos;
				return true;
			}
			return false;
		}

		public bool SetCurNegativeEndPoint(XYZ ptCurNodePos, XYZ ptNewPos)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				this.m_ptNegativeEnd = ptNewPos;
				return true;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				this.m_ptPositiveStart = ptNewPos;
				return true;
			}
			return false;
		}

		public bool SetCurVariableCross_SectionInPositiveStartPoint(XYZ ptCurNodePos, Edge newCrossSection)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				this.m_VariableCross_SectionInPositiveStart = newCrossSection;
				return true;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				this.m_VariableCross_SectionInNegativeEnd = newCrossSection;
				return true;
			}
			return false;
		}

		public bool SetCurVariableCross_SectionInPositiveEndPoint(XYZ ptCurNodePos, Edge newCrossSection)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				this.m_VariableCross_SectionInPositiveEnd = newCrossSection;
				return true;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				this.m_VariableCross_SectionInNegativeStart = newCrossSection;
				return true;
			}
			return false;
		}

		public bool SetCurVariableCross_SectionInNegativeStartPoint(XYZ ptCurNodePos, Edge newCrossSection)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				this.m_VariableCross_SectionInNegativeStart = newCrossSection;
				return true;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				this.m_VariableCross_SectionInPositiveEnd = newCrossSection;
				return true;
			}
			return false;
		}

		public bool SetCurVariableCross_SectionInNegativeEndPoint(XYZ ptCurNodePos, Edge newCrossSection)
		{
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				this.m_VariableCross_SectionInNegativeEnd = newCrossSection;
				return true;
			}
			if (tagPositionType == Structure2DPole._tagPositionType._EndNode)
			{
				this.m_VariableCross_SectionInPositiveStart = newCrossSection;
				return true;
			}
			return false;
		}

		public double GetLengthCurrentEndToPoint(XYZ ptCurNodePos, XYZ point)
		{
			double result = 0.0;
			XYZ xyz = XYZ.Zero;
			Structure2DPole._tagPositionType tagPositionType = this.TestPointPositionType(ptCurNodePos);
			bool flag = true;
			if (tagPositionType == Structure2DPole._tagPositionType._StartNode)
			{
				xyz = this.m_ptStart;
			}
			else
			{
				if (tagPositionType != Structure2DPole._tagPositionType._EndNode)
				{
					return result;
				}
				flag = false;
				xyz = this.m_ptEnd;
			}
			if (this.IsArcPole)
			{
				XYZ center = this.Center;
				if (Geometry.LessThan(this.m_Bulge, 0.0))
				{
					flag = !flag;
				}
				double angle = Geometry.getAngle(center, xyz);
				double angle2 = Geometry.getAngle(center, point);
				double num;
				if (flag)
				{
					num = Geometry.BetweenTheAngles(angle, angle2, true);
				}
				else
				{
					num = Geometry.BetweenTheAngles(angle2, angle, true);
				}
				result = num * this.Radius;
			}
			else
			{
				result = xyz.DistanceTo(point);
			}
			return result;
		}

		public Curve ToCurve(Document doc, bool isBound)
		{
			if (this.IsArcPole)
			{
				XYZ xyz = XYZ.BasisZ;
				if (Geometry.LessThan(this.Bulge, 0.0))
				{
					xyz = -xyz;
				}
				if (isBound)
				{
					XYZ xyz2 = Geometry.CalculatMidPoint(this.StartPoint, this.EndPoint, this.Center, xyz);
					return Arc.Create(this.StartPoint, this.EndPoint, xyz2);
				}
				XYZ center = this.Center;
				double radius = this.Radius;
				XYZ xyz3 = center - XYZ.BasisX * radius;
				XYZ xyz4 = center + Geometry.RotateTo(XYZ.BasisX, 3.12413936106985, xyz) * radius;
				XYZ xyz5 = center + XYZ.BasisX * radius;
				return Arc.Create(xyz3, xyz4, xyz5);
			}
			else
			{
				if (isBound)
				{
					return YJKLineEx.YJKGetBound(this.StartPoint, this.EndPoint);
				}
				return YJKLineEx.YJKGetUnBound(this.StartPoint, this.EndPoint - this.StartPoint);
			}
		}

		protected Structure2DPole()
		{
		}

		public Structure2DPole(Structure2DPole rhs)
		{
			this.m_ComponentId = rhs.m_ComponentId;
			this.m_ptStart = rhs.m_ptStart;
			this.m_ptEnd = rhs.m_ptEnd;
			this.m_Bulge = rhs.m_Bulge;
			this.m_ptPositiveStart = rhs.m_ptPositiveStart;
			this.m_ptPositiveEnd = rhs.m_ptPositiveEnd;
			this.m_ptNegativeStart = rhs.m_ptNegativeStart;
			this.m_ptNegativeEnd = rhs.m_ptNegativeEnd;
			this.m_PositiveDirection = rhs.m_PositiveDirection;
			this.m_ptStartNodePosition = this.m_ptStart;
			this.m_ptEndNodePosition = this.m_ptEnd;
			this.m_VariableCross_SectionInPositiveStart = rhs.m_VariableCross_SectionInPositiveStart;
			this.m_VariableCross_SectionInPositiveEnd = rhs.m_VariableCross_SectionInPositiveEnd;
			this.m_VariableCross_SectionInNegativeStart = rhs.m_VariableCross_SectionInNegativeStart;
			this.m_VariableCross_SectionInNegativeEnd = rhs.m_VariableCross_SectionInNegativeEnd;
		}

		public Structure2DPole(ElementId componentId, XYZ ptStart, XYZ ptEnd, double bulge, XYZ ptPositiveStart, XYZ ptPositiveEnd, XYZ ptNegativeStart, XYZ ptNegativeEnd, bool positiveDirection)
		{
			this.m_ComponentId = componentId;
			this.m_ptStart = ptStart;
			this.m_ptEnd = ptEnd;
			this.m_Bulge = bulge;
			this.m_ptPositiveStart = ptPositiveStart;
			this.m_ptPositiveEnd = ptPositiveEnd;
			this.m_ptNegativeStart = ptNegativeStart;
			this.m_ptNegativeEnd = ptNegativeEnd;
			this.m_PositiveDirection = positiveDirection;
			this.m_ptStartNodePosition = this.m_ptStart;
			this.m_ptEndNodePosition = this.m_ptEnd;
		}

		public static Structure2DPole NewStructure2DPole(ElementId id, XYZ ptStart, XYZ ptEnd, double posiHalfWidth, double negaHalfWidth)
		{
			XYZ xyz = Geometry.RotateTo((ptEnd - ptStart).Normalize(), -Math.PI*.5, XYZ.BasisZ);
			XYZ xyz2 = xyz.Negate();
			xyz *= posiHalfWidth;
			xyz2 *= negaHalfWidth;
			XYZ ptPositiveStart = ptStart + xyz;
			XYZ ptPositiveEnd = ptEnd + xyz;
			XYZ ptNegativeStart = ptStart + xyz2;
			XYZ ptNegativeEnd = ptEnd + xyz2;
			return new Structure2DPole(id, ptStart, ptEnd, 0.0, ptPositiveStart, ptPositiveEnd, ptNegativeStart, ptNegativeEnd, true);
		}

		public static Structure2DPole NewStructure2DPole(ElementId id, XYZ ptStart, XYZ ptEnd, XYZ ptCenter, XYZ normal, double posiHalfWidth, double negaHalfWidth)
		{
			if (!normal.IsAlmostEqualTo(XYZ.BasisZ, 0.0001))
			{
				XYZ xyz = ptStart;
				ptStart = ptEnd;
				ptEnd = xyz;
			}
			double bulge = Geometry.GetBulge(ptStart, ptEnd, ptCenter, true);
			double num = ptCenter.DistanceTo(ptStart);
			XYZ xyz2 = (ptStart - ptCenter).Normalize() * (num + posiHalfWidth);
			XYZ xyz3 = (ptEnd - ptCenter).Normalize() * (num + posiHalfWidth);
			XYZ xyz4 = (ptStart - ptCenter).Normalize() * (num - negaHalfWidth);
			XYZ xyz5 = (ptEnd - ptCenter).Normalize() * (num - negaHalfWidth);
			XYZ ptPositiveStart = ptCenter + xyz2;
			XYZ ptPositiveEnd = ptCenter + xyz3;
			XYZ ptNegativeStart = ptCenter + xyz4;
			XYZ ptNegativeEnd = ptCenter + xyz5;
			return new Structure2DPole(id, ptStart, ptEnd, bulge, ptPositiveStart, ptPositiveEnd, ptNegativeStart, ptNegativeEnd, true);
		}

		public static Structure2DPole TransformWallToStructure2DPole(Wall wall)
		{
			double width = wall.Width;
			Structure2DPole result = null;
			Curve curve = (wall.Location as LocationCurve).Curve;
			XYZ hyendPoint = curve.GetEndPoint(0);
			XYZ hyendPoint2 = curve.GetEndPoint(1);
			Line line = curve as Line;
			if (null != line)
			{
				result = Structure2DPole.NewStructure2DPole(wall.Id, hyendPoint, hyendPoint2, width / 2.0, width / 2.0);
			}
			Arc arc = curve as Arc;
			if (null != arc)
			{
				result = Structure2DPole.NewStructure2DPole(wall.Id, hyendPoint, hyendPoint2, arc.Center, arc.Normal, width / 2.0, width / 2.0);
			}
			return result;
		}

		public static Structure2DPole TransformWallToStructure2DPole(Curve curve, ElementId id, double posiWidth, double negaWidth)
		{
			Structure2DPole result = null;
			XYZ hyendPoint = curve.GetEndPoint(0);
			XYZ hyendPoint2 = curve.GetEndPoint(1);
			Line line = curve as Line;
			if (null != line)
			{
				result = Structure2DPole.NewStructure2DPole(id, hyendPoint, hyendPoint2, posiWidth, negaWidth);
			}
			Arc arc = curve as Arc;
			if (null != arc)
			{
				result = Structure2DPole.NewStructure2DPole(id, hyendPoint, hyendPoint2, arc.Center, arc.Normal, posiWidth, negaWidth);
			}
			return result;
		}

		protected ElementId m_ComponentId;

		protected XYZ m_ptStart;

		protected XYZ m_ptEnd;

		protected double m_Bulge;

		protected XYZ m_ptPositiveStart;

		protected XYZ m_ptPositiveEnd;

		protected XYZ m_ptNegativeStart;

		protected XYZ m_ptNegativeEnd;

		protected bool m_PositiveDirection = true;

		protected XYZ m_ptStartNodePosition;

		protected XYZ m_ptEndNodePosition;

		protected Edge m_VariableCross_SectionInPositiveStart;

		protected Edge m_VariableCross_SectionInPositiveEnd;

		protected Edge m_VariableCross_SectionInNegativeStart;

		protected Edge m_VariableCross_SectionInNegativeEnd;

		public enum _tagPositionType
		{
			_StartNode,
			_EndNode,
			_OtherPoint
		}

		public enum _tagSideLineValidType
		{
			_Valide,
			_Reversed,
			_ZeroLength
		}
	}
}
